<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">

<div id="id_panel">
</div>
<script th:inline="javascript">
	var dto = $.parseJSON(JSON.stringify([[${dto}]]));

	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
				form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal;
		/*
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
				{
					id:'id_panel', // 页面容器ID
					dto: dto
				}
		);


		/*
		 * 监听币种输入框
		 */
		var domForm = $('#' + window.formObj.c.id_form);
		domForm.find('input[name="assembleNum"]').on('change',function (e) {
			calFormItem();
		});



	});


</script>

<script>


	/*
	 * 自动计算表单数据
	 */
	function calFormItem() {

		var domForm = $('#' + window.formObj.c.id_form);
		var assembleNum = domForm.find('input[name="assembleNum"]').val();
		var sonlist = formObj.c.subGridObj.c.sonlist;
		for (var i = 0; i < sonlist.length; i++) {
			formObj.c.subGridObj.c.sonlist[i]['subNeedNum'] = assembleNum?(parseFloat(assembleNum) * parseFloat(formObj.c.subGridObj.c.sonlist[i]['subBomNum'])).toFixed(0):0
		}
		formObj.c.subGridObj.reloadGrid();

	}


	function opeTplScript(subCode){
		console.log('---------subCode---------',subCode);

		var sonlist = formObj.c.subGridObj.c.sonlist;
		//console.log('---------sonlist---------',sonlist);
		var isSame = false;
		for (var i = 0; i < sonlist.length; i++) {
			if(sonlist[i].subCode == subCode){
				isSame = true;
			}
			if(isSame && sonlist[i].subCode != subCode ){
				var row = sonlist[i-1];
				var addRow ={
					productCode:row.productCode,
					subCode:row.subCode,
					subName:row.subName,
					subBomNum:row.subBomNum,
					subNeedNum:row.subNeedNum,
				};
				formObj.c.subGridObj.c.sonlist.splice(i, 0, addRow);
				isSame = false;
			}

		}
		if(isSame){
			var row = sonlist[sonlist.length-1];
			var addRow ={
				productCode:row.productCode,
				subCode:row.subCode,
				subName:row.subName,
				subBomNum:row.subBomNum,
				subNeedNum:row.subNeedNum,
			};
			formObj.c.subGridObj.c.sonlist.push(addRow);
			isSame = false;
		}
		formObj.c.subGridObj.reloadGrid();
	}



</script>


</body>
</html>